package cz.data.domain.market.controller;

import cz.data.common.base.BaseController;
import cz.data.common.core.DataConstant;
import cz.data.common.annotation.DataInner;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import cz.data.domain.market.model.entity.ApiMaskEntity;
import cz.data.domain.market.model.entity.DataApiEntity;
import cz.data.domain.market.model.entity.TableApiEntity;
import cz.data.domain.market.service.ApiMaskService;
import cz.data.domain.market.service.DataApiService;
import cz.data.domain.market.service.TableApiService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Api(tags = {"内部接口"}, hidden = true)
@RestController
@RequestMapping("/inner")
public class InnerController extends BaseController {

    @Autowired
    private DataApiService dataApiService;

    @Autowired
    private ApiMaskService apiMaskService;

    @Autowired
    private TableApiService tableApiService;

    @DataInner
    @GetMapping("/apis/{id}")
    public DataApiEntity getDataApiById(@PathVariable("id") String id) {
        return dataApiService.getDataApiById(id);
    }

    @DataInner
    @GetMapping("/apis/release/list")
    public List<DataApiEntity> getReleaseDataApiList() {
        QueryWrapper<DataApiEntity> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("status", DataConstant.ApiState.RELEASE.getKey());
        return dataApiService.list(queryWrapper);
    }

    @DataInner
    @GetMapping("/apiMasks/api/{id}")
    public ApiMaskEntity getApiMaskByApiId(@PathVariable("id") String id) {
        return apiMaskService.getApiMaskByApiId(id);
    }

    @DataInner
    @GetMapping("/table/api/{id}")
    public TableApiEntity getTableApiById(@PathVariable("id") String id) {
        return tableApiService.getTableApiById(id);
    }

    @DataInner
    @GetMapping("/table/api/release/list")
    public List<TableApiEntity> releaseTableApiList() {
        QueryWrapper<TableApiEntity> wrapper = new QueryWrapper<>();
        wrapper.lambda().eq(TableApiEntity::getStatus, DataConstant.ApiState.RELEASE.getKey());
        return tableApiService.list(wrapper);
    }
}
